package com.bjtu.lms.action.borrow;

import com.bjtu.lms.service.BorrowService;
import com.opensymphony.xwork2.ActionSupport;

/**
 *
 * @author yilee
 */
public class BorrowBookAction extends ActionSupport {

	private String userId;
	private String bookId;
	private BorrowService borrowService;
	private String result;

	public String getBookId() {
		return bookId;
	}

	public void setBookId(String bookId) {
		this.bookId = bookId;
	}

	public BorrowService getBorrowService() {
		return borrowService;
	}

	public void setBorrowService(BorrowService borrowService) {
		this.borrowService = borrowService;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	@Override
	public String execute() throws Exception {
		int book_id, user_id;
		try {
			book_id = Integer.parseInt(bookId);
			user_id = Integer.parseInt(userId);
		} catch (Exception e) {
			result = "{suc:0, msg:'ID必须为整数'}";
			return SUCCESS;
		}
		result = borrowService.borrow(user_id, book_id);
		return SUCCESS;
	}
}
